/*
 * GeneradorServiciosSeleccion.fx
 *
 * Created on 13-may-2009, 22:13:45
 */

package webooksfx_desktop.view.components;

import javafx.scene.CustomNode;
import javafx.scene.Group;
import javafx.scene.Node;
import webooksfx.model.Servicio;
/**
 * @author Administrador
 */
public class GeneradorServiciosSeleccion extends CustomNode {
	public var width : Integer = 128;
	public var height : Integer = 128;
	public var margin : Integer = 100;
	public var action : function ( s : Servicio ) : Void;
	public var servicios : Servicio[] = null;
	public var servicioSeleccionado : Servicio = null;
	public var itemsXFila : Integer = 2;

	public override function create(): Node {
		var columna : Integer = -1;
		var fila : Integer = 0;
		var item : Integer = -1;
		var grp : Node;
		grp = Group {
			content: [
				for ( servicio in servicios ){
					item++;
					columna++;
					if ( columna > itemsXFila-1 ) {
						columna = 0;
						fila++;
					}
					ServiceSelection{
						translateX: (width * columna) + (margin * columna)
						translateY: (height * fila) + (margin * fila)
						width:128
						height:128
						servicio: servicios[item];
						servicioSeleccionado: bind servicioSeleccionado
						action: action
					}
				}
			]			
		};
		return grp;
	}
}